//
//  WebViewViewController.m
//  WebView
//

#import "WebViewViewController.h"

UIActivityIndicatorView *activity;

@implementation WebViewViewController

- (void)viewDidLoad {
    [super viewDidLoad];
	
	[self.view setBackgroundColor:[UIColor blackColor]];
	
	CGRect webRect = CGRectMake(10, 10, 300, 380);
	UIWebView *myWebView = [[UIWebView alloc] initWithFrame:webRect];
	myWebView.scalesPageToFit = YES;
	
	myWebView.delegate = self;
	
	NSURL *url = [NSURL URLWithString:@"http://www.google.com"];
	NSURLRequest *request = [NSURLRequest requestWithURL:url];
	[myWebView loadRequest:request];
	
	[self.view addSubview:myWebView];
	
	activity = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
	[activity setCenter:CGPointMake(160, 420)];
	[self.view addSubview:activity];
	
	[myWebView release];
}

- (void)webViewDidStartLoad:(UIWebView *)webView {
	[activity startAnimating];
}

- (void)webViewDidFinishLoad:(UIWebView *)webView {
	[activity stopAnimating];
	[webView stringByEvaluatingJavaScriptFromString:@"alert('Finished Loading!');"];
}

- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error {
	[activity stopAnimating];
	NSLog(@"Error: %@", error);
}

- (void)dealloc {
    [super dealloc];
}

@end
